<?php

namespace App\Http\Controllers\Home;
use Gregwar\Captcha\CaptchaBuilder;
use Illuminate\Http\Request;
use App\Http\Requests\UserRegistRequest;
use Hash;
use DB;
use App\Http\Requests;
use App\Http\Controllers\Controller;

class ShouyeController extends Controller
{

	//首页
	public function index()
	{
		$user=DB::table('users')->where('uid',session('uid'))->first();
		$nba=DB::table('block')->where('sname','NBA区')->get();
		// dd($nba);
		$deal=DB::table('block')->where('sname','交易区')->get();
		$skill=DB::table('block')->where('sname','技术区')->get();
		$news=DB::select('select * from news order by nid desc limit 20');
		$order=DB::select('select * from post order by ctr desc limit 10');
		$goods=DB::select('select * from goods order by gview desc limit 10');
		// dd($goods);
		return view('home.homepage.homepage',['user'=>$user,'nba'=>$nba,'deal'=>$deal,'skill'=>$skill,'news'=>$news,'order'=>$order,'goods'=>$goods]);
	}

	//加关注
	public function getGuanzhu(Request $request)
	{
		$bid=$request->input('bid');		
		if(session('uid')){
			$cun=DB::table('person')->where('uid',session('uid'))->get();
			$cuns=[];
			foreach($cun as $k=>$v){
				$cuns[$k]=$v->bid;
			}

			// dd(!in_array($bid,$cuns));
			if(!in_array($bid,$cuns)){
				$res=DB::table('person')->insert(
				    ['bid' => $bid,'uid' => session('uid')]
				);
				if($res){
					echo 2;//关注成功
				}else{
					echo 3;//关注失败
				}
			}else{
				echo 1;//已关注
			}			
		}else{
			echo 0;//请登录
		}
	}





	

}
